﻿using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AutoFlatnessTest.ViewModel
{
    public class MainWindowVModel : BindableBase
    {
        private string info;

        public string Info
        {
            get { return info; }
            set { info = value; RaisePropertyChanged(nameof(Info)); }
        }

        private bool isJinGao = false;
        /// <summary>
        /// 是否显示警告
        /// </summary>
        public bool IsJinGao
        {
            get { return isJinGao; }
            set { isJinGao = value; RaisePropertyChanged(nameof(IsJinGao)); }
        }


        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; RaisePropertyChanged(nameof(Time)); }
        }

        private bool isTbCw = false;

        public bool IsTbCw
        {
            get { return isTbCw; }
            set { SetProperty(ref isTbCw, value); }
        }

        private bool isTbJz = false;

        public bool IsTbJz
        {
            get { return isTbJz; }
            set { SetProperty(ref isTbJz, value); }
        }

        private string tbInfo = "";

        public string TbInfo
        {
            get { return tbInfo; }
            set { SetProperty(ref tbInfo, value); }
        }

        public string TbErr { get; set; }

        public void RunTime()
        {
            _ = Task.Run(() =>
            {
                while (true)
                {
                    Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    Thread.Sleep(1000);
                }
            });
        }

        public void SetTbIn()
        {
            IsTbCw = false;
            IsTbJz = true;
            TbInfo = "正在同步数据...";
            TbErr = "";
        }

        public void SetTbOk()
        {
            IsTbCw = false;
            IsTbJz = false;
            TbInfo = "";
            TbErr = "";
        }

        public void SetTbErr(string err)
        {
            IsTbCw = true;
            IsTbJz = false;
            TbInfo = "同步数据失败";
            TbErr = err;
        }

    }
}
